<?php namespace Admin\Model;
class Pics extends \Hdphp\Model\Model{
	protected $table = "shop_pics";

	protected $auto=array(
        // array('logo','getLogo','method',3,3),
		);

	//删除图集图片
	public function remove($id)
	{
		//删除图片文件
		$pic = $this->find($id);
		is_file($pic['big_pic']) and unlink($pic['big_pic']);
		is_file($pic['midd_pic']) and unlink($pic['midd_pic']);
		is_file($pic['small_pic']) and unlink($pic['small_pic']);

		//删除表数据
		return $this->where('id',$id)->delete();
	}

	//添加商品图集
	//根据$_FILES数据插入到表中
	public function store($goods_id)
	{
		//处理图集
		$pics = Upload::make('pics');

		foreach((array)$pics as $f)
		{
					//生成中图
			$middFile = $f['dir'].'/'.$f['filename'].'_middle.'.$f['ext'];
			Image::thumb($f['path'],$middFile,400,400,6);
					//生成小图
			$smallFile = $f['dir'].'/'.$f['filename'].'_small.'.$f['ext'];
			Image::thumb($f['path'],$smallFile,150,150,6);

					//入库
			$data['big_pic']=$f['path'];
			$data['midd_pic']=$middFile;
			$data['small_pic']=$smallFile;
			$data['goods_id']=$goods_id;
			Db::table('shop_pics')->insert($data);
		}
		return true;
	}

}













